//
//  View+Router.swift
//  SwiftuiUno
//
//  Created by hccc on 2023/11/20.
//

import Foundation
import SwiftUI
/// 路由列表
enum RouterDestination: Hashable {
    case phoneLogin
    case captureCamera
    case editCase(camera: CaptureLogic)
    case passwordLogin(type: SignType, phone: String, areaCode: String)
    case smscodeLogin(phone: String, areaCode: String, signType: SignType, password: String?)
    case aboutUS
    case deleteAccount
}
@MainActor
extension View {
    func withAppRouter() -> some View {
        return navigationDestination(for: RouterDestination.self) { info in
            switch info {
            case .phoneLogin:
                PhoneInputLoginPage()
            case .captureCamera:
                CaptureCaseView()
            case .editCase(camera: let camera):
                EditCaseView().environmentObject(camera)
            case let .passwordLogin(type, phone, areaCode):
                PwdInputToLoginPage(phone: phone, areaCode: areaCode, type: type)
            case let .smscodeLogin(phone, areaCode, signType, password):
                SmscodeLoginPage(phone: phone, areaCode: areaCode, signType: signType, password: password)
            case .aboutUS:
                AboutUsPage()
            case .deleteAccount:
                DeleteAccountPage()
            }
        }
    }
}

@MainActor
extension View {
}

extension View {
    /// 返回按钮配置
    /// - Parameter router:
    /// - Returns:
    func setupBackItem(_ router: Router) -> some View {
        navigationBarBackButtonHidden()
            .toolbar {
                ToolbarItem(id: "back", placement: .topBarLeading) {
                    Image(systemName: "chevron.backward")
                        .paddingRight(15)
                        .onTapGesture {
                            DispatchQueue.main.async {
                                router.back()
                            }
                        }
                }
            }
    }
}

